module Kernel
  alias_method :old_require, :require
  def require(name)
    # Don't benchmark requires outside of this project
    return old_require(name) if name.start_with?('/')

    # Store a local variable for the result of the benchmark, so the original
    # method can return true/false as it would have.
    old_result = false

    # Profile the result
    RuSlow.add("require '#{name}'", Benchmark.measure { old_result = old_require(name) })

    # Return the original result
    return old_result
  end

  alias_method :old_load, :load
  def load(name, wrap = false)
    # Don't benchmark requires outside of this project
    return old_load(name) if name.start_with?('/')

    # Profile the result
    RuSlow.add("load '#{name}'", Benchmark.measure { old_load(name, wrap) })

    # ALways return true
    return true
  end
end

Kernel.at_exit do
  RuSlow.report!
end
